public class TC2 {
        public static void main(String[] args) {
            // (1) 创建SelfDrivingTravel对象，7天，车型为1（小轿车）
            TravelMethod travelMethod = new SelfDrivingTravel(7, 1);
            travelMethod.showTravelInfo();
            System.out.println("旅行费用:" + travelMethod.calculatePrice() + "元");
        }
    }

    // (2) 抽象类TravelMethod定义
    abstract class TravelMethod {
        protected int days;

        public TravelMethod(int days) {
            this.days = days;
        }

        public abstract void showTravelInfo();

        public abstract double calculatePrice();
    }

    // (3) 在构造函数中初始化父类的days属性
    class SelfDrivingTravel extends TravelMethod {
        private int carType;

        public SelfDrivingTravel(int days, int carType) {
            super(days);
            this.carType = carType;
        }

        // (4) 实现showTravelInfo方法
        @Override
        public void showTravelInfo() {
            System.out.println("出行方式:自驾游");
            System.out.println("出行天数:" + days);
            System.out.println("车型:" + (carType == 1? "小轿车" : "越野车"));
        }

        @Override
        public double calculatePrice() {
            double basePrice = carType == 1? 500.0 : 800.0;
            double pricePerDay = carType == 1? 50.0 : 80.0;
            return basePrice + days * pricePerDay;
        }

}
